{% load i18n simplewiki_utils %}
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
<html lang="ru" xmlns="http://www.w3.org/1999/xhtml" xml:lang="ru">
<head>
<title>{{ wiki_title }}</title>
<META http-equiv=Content-Type content="text/html; charset=UTF-8">
<link rel="stylesheet" media="screen,print" href="{{ STATIC_URL }}simplewiki/css/base.css" />
<link rel="stylesheet" media="print" href="{{ STATIC_URL }}simplewiki/css/base_print.css" />
<link rel="stylesheet" href="{{ STATIC_URL }}simplewiki/css/autosuggest_inquisitor.css" />
<link rel="stylesheet" href="{{ STATIC_URL }}globalmenu.css" />
<script type="text/javascript" src="{{ STATIC_URL }}simplewiki/js/bsn.AutoSuggest_c_2.0.js"></script>
<script type="text/javascript">
function set_related_article_id(s) {
    document.getElementById('wiki_related_input_id').value = s.id;
    document.getElementById('wiki_related_input_submit').disabled=false;
}
var x = window.onload;
window.onload = function(){
        var options = {
        script: "{% url search_related wiki_article.get_url %}?self={{wiki_article.pk }}&",
        json: true,
        varname: "query",
        maxresults: 35,
        callback: set_related_article_id,
        noresults: "Ничего не найдено!"
    };
    var as = new AutoSuggest('wiki_related_input', options);
    if (typeof x == 'function')
        x();
}

var rusChars = new Array('А','Б','В','Г','Д','Е','Ё','Ж','З','И','Й','К','Л','М','Н','О','П','Р','С','Т','У','Ф','Х','Ц','Ч','Ш','Щ','Ъ','Ы','Ь','Э','Ю','Я','а','б','в','г','д','е','ё','ж','з','и','й','к','л','м','н','о','п','р','с','т','у','ф','х','ц','ч','ш','щ','ъ','ы','ь','э','ю','\я');
var transChars = new Array('A','B','V','G','D','E','YO','ZH','Z','I','J','K','L','M','N','O','P','R','S','T','U','F','H','C','CH','SH','SHCH','\`','Y','\'','E','YU','YA','a','b','v','g','d','e','yo','zh','z','i','j','k','l','m','n','o','p','r','s','t','u','f','h','c','ch','sh','shch','\`','y','\'','e','yu','ya');
function trans(from)
{
  var to = new String();
  var len = from.length;
  var character, isRus;
  for(i=0; i < len; i++)
  {
    character = from.charAt(i,1);
    isRus = false;
    for(j=0; j < rusChars.length; j++)
    {
      if(character == rusChars[j])
      {
        isRus = true;
        break;
      }
    }
    to += (isRus) ? transChars[j] : character;
  }
  //document.m_form.message.value = to;
  //document.m_form.message.focus();
  return to;
}

    
</script>
{% block wiki_head %}
{% endblock %}
</head>
<body>

{% include "globalmenu.html" %}

<h1>{% block wiki_page_title %}{% endblock %}</h1>
<hr />

{% block wiki_panel %}

<div id="wiki_panel">
    
    <div class="wiki_box">
    	<div class="wiki_box_contents border_shadow">
        	<div class="wiki_box_title">Поиск</div>
            <form method="POST" action='{% url wiki_search_articles wiki_article.get_url %}'>{% csrf_token %}
            	<input type="text" name="value" id="wiki_search_input" value="{{wiki_search_query|escape}}"/>
            	<input type="submit" id="wiki_search_input_submit" value="Найти" />
            </form>
        </div>
    </div>
    
    {% if user.is_authenticated %}
    <div class="wiki_box">
    	<div class="wiki_box_contents border_shadow" style="position: relative;">
        <div class="wiki_box_title">Управление</div>
    	<div style="border: 2px outset #CCC; width: 250px; padding: 10px; background-color: #FFF; position: absolute; right: 100px; top: -80px; display: none; color: #000;" id="wiki_create_form">
    	    {% with "trans(this.wiki_article_name.value).replace(/([^a-zA-Z0-9\-])/g, '')+'/_create/'" as theaction %}
    		<form method="GET" onsubmit="this.action='{% url wiki_view "" %}{{ wiki_article.get_url }}/' + {{ theaction }};">
    		{% endwith %}
    			<h2>Новая статья</h2>
    			<p>
    			    <label for="id_wiki_article_name">Заголовок статьи</label>
    			    <input type="text" name="wiki_article_name" id="id_wiki_article_name" /><br/>
    			    <label for="id_wiki_article_is_child">Как дочернюю к текущей статье</label>
    			    <input type="checkbox" name="wiki_article_is_child" id="id_wiki_artcile_is_child" disabled="true" checked={%if wiki_article%}"yes"{%else%}"no"{%endif%}>
    			</p>
    			<p>
    				<input type="button" class="button" value="Отмена" style="display: inline-block; margin-right: 2px;" onclick="document.getElementById('wiki_create_form').style.display='none';" />
    				<input type="submit" class="button" value="Далее &gt;" style="display: inline-block; margin-right: 2px; font-weight: bold;" />
    			</p>
    		</form>
    	</div>
    	<p>
    	
	    {% if wiki_article %} 
    	    <input type="button" onclick="javascript:location.href='{% url wiki_view wiki_article.get_url %}'" value="Просмотр" style="width: 100%;" /><br />
    	    <input type="button" onclick="javascript:location.href='{% url wiki_edit wiki_article.get_url %}'" value="Править" style="width: 100%;"{% if not wiki_write %} disabled="true"{%endif%} /><br />
    	    <input type="button" onclick="javascript:location.href='{% url wiki_history wiki_article.get_url 1 %}'" value="История" style="width: 100%;" />
    	{% endif %}
    	<input type="button" onclick="document.getElementById('wiki_create_form').style.display='block';" value="Новая статья" style="width: 100%; margin-bottom: 2px;" class="button" />
    	<input type="button" onclick="javascript:location.href='{% url wiki_random wiki_article.get_url %}'" value="Случайная статья" style="width: 100%; margin-bottom: 2px;" class="button" />
    	</p>
	    {% if wiki_article %} 
    	    {% if wiki_article.locked %}
    	    <p><strong>Эта статья заблокирована</strong></p>
    	    {% endif %}
    	    <p>
    	        <i>Последние изменения:<BR/>{{ wiki_article.modified_on|date:"j N Y" }}г, {{ wiki_article.modified_on|time:"G i" }}</i>
    	    </p>
        {% endif %}
    	</div>
    </div>
    {% endif %}
    

    {% if wiki_article %}   
  
        <div class="wiki_box">
        	<div class="wiki_box_contents border_shadow">
        	<div class="wiki_box_title">Связанные статьи</div>
        {% if wiki_article.related.all %}
        	<p>
        		{% for rel in wiki_article.related.all %}
        		<span class="related">
        			{% if wiki_write %}
        				<a href="javascript:if(confirm('Вы уверены что хотите удалить эту связь?')) { location.href='{% url wiki_remove_relation wiki_article.get_url rel.id%}'; }">
        					<img src="{{ STATIC_URL }}simplewiki/img/delete.gif" alt="Удалить связь" />
        				</a>
        			{% endif %}
        			<a href="{% url wiki_view rel.get_url %}">{{rel.title}}</a>
        		</span>
        		{% endfor %}
        	</p>
        {% else %}
        	<p><i>(Нет)</i></p>
        {% endif %}
        {% if user.is_authenticated %}
        {% if wiki_write %}
        <form method="POST" action="{% url add_related wiki_article.get_url %}">{% csrf_token %}
        	<input type="text" name="value" id="wiki_related_input" />
        	<input type="submit" id="wiki_related_input_submit" disabled="true" value="Добавить" />
        	<input type="hidden" name="id" value="" id="wiki_related_input_id" />
        </form>
        {% endif %}
        {% endif %}
        	</div>
        </div> 

        <div class="wiki_box">
        	<div class="wiki_box_contents border_shadow">
        	<div class="wiki_box_title">Вложения</div>
        	{% if wiki_article.attachments %}
        	<ul>
        		{% for a in wiki_article.attachments %}
        		<li><a href="{{a.download_url}}">{{a.filename|slice:":13"|slice:":-3" }}{% if a.filename|slice:"10:" %}...{{ a.filename|slice:"-3:" }}{% endif %}</a> ({{a.get_size|filesizeformat}})</li>
        		{% endfor %}
        	</ul>
        	{% else %}
        	<p><i>(Нет)</i></p>
        	{% endif %}
        	
        {% if wiki_attachments_write %}
        	<form method="POST" action="{% url add_attachment wiki_article.get_url %}" enctype="multipart/form-data" target="wiki_attach_frame">{% csrf_token %}
        		<input type="file" class="fileinput" name="attachment" size="20"/><br />
        		<input type="checkbox" name="overwrite" id="wiki_attach_overwrite" value="1" /> Заменить с тем-же именем.
        		<p><input type="submit" value="Вложить" /></p>
        		<div id="wiki_attach_progress_container">
        			<div id="wiki_attach_progress"><br /></div>
        		</div>
        	</form>
        	<iframe name="wiki_attach_frame" style="display:none"></iframe>
        {% endif %}
        	</div>
        </div>
    {% endif %}

</div>

{% endblock %}

{% block wiki_body %}

{% endblock %}

</body>
</html>
